home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games Extra 1996 September / Amiga Games Extra CD-ROM 9-1996.iso / userbox / publicdomain / vim-4.2 / src / structs.h < prev    next >
C/C++ Source or Header  |  1996-06-09  |  17KB  |  551 lines

  1. /* vi:set ts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved        by Bram Moolenaar
  4.  *
  5.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  6.  * Do ":help credits" in Vim to see a list of people who contributed.
  7.  */
  8.  
  9. /*
  10.  * This file contains various definitions of structures that are used by Vim
  11.  */
  12.  
  13. /*
  14.  * file position
  15.  */
  16.  
  17. typedef struct fpos        FPOS;
  18. /*
  19.  * there is something wrong in the SAS compiler that makes typedefs not
  20.  * valid in include files
  21.  */
  22. #ifdef SASC
  23. typedef long            linenr_t;
  24. typedef unsigned        colnr_t;
  25. typedef unsigned short    short_u;
  26. #endif
  27.  
  28. struct fpos
  29. {
  30.     linenr_t        lnum;            /* line number */
  31.     colnr_t         col;            /* column number */
  32. };
  33.  
  34. /*
  35.  * Sorry to put this here, but gui.h needs the FPOS type, and WIN needs gui.h
  36.  * for GuiScrollbar.  There is probably somewhere better it could go -- webb
  37.  */
  38. #ifdef USE_GUI
  39. # include "gui.h"
  40. #endif
  41.  
  42. /*
  43.  * marks: positions in a file
  44.  * (a normal mark is a lnum/col pair, the same as a file position)
  45.  */
  46.  
  47. #define NMARKS            26            /* max. # of named marks */
  48. #define JUMPLISTSIZE    30            /* max. # of marks in jump list */
  49. #define TAGSTACKSIZE    20            /* max. # of tags in tag stack */
  50.  
  51. struct filemark
  52. {
  53.     FPOS            mark;            /* cursor position */
  54.     int                fnum;            /* file number */
  55. };
  56.  
  57. /*
  58.  * the taggy struct is used to store the information about a :tag command:
  59.  *    the tag name and the cursor position BEFORE the :tag command
  60.  */
  61. struct taggy
  62. {
  63.     char_u            *tagname;            /* tag name */
  64.     struct filemark fmark;                /* cursor position */
  65. };
  66.  
  67. /*
  68.  * line number list
  69.  */
  70.  
  71. /*
  72.  * Each window can have a different line number associated with a buffer.
  73.  * The window-pointer/line-number pairs are kept in the line number list.
  74.  * The list of line numbers is kept in most-recently-used order.
  75.  */
  76.  
  77. typedef struct window        WIN;
  78. typedef struct winlnum        WINLNUM;
  79.  
  80. struct winlnum
  81. {
  82.     WINLNUM        *wl_next;            /* next entry or NULL for last entry */
  83.     WINLNUM        *wl_prev;            /* previous entry or NULL for first entry */
  84.     WIN            *wl_win;            /* pointer to window that did set wl_lnum */
  85.     linenr_t     wl_lnum;            /* last cursor line in the file */
  86. };
  87.  
  88. /*
  89.  * stuctures used for undo
  90.  */
  91.  
  92. struct u_entry
  93. {
  94.     struct u_entry    *ue_next;    /* pointer to next entry in list */
  95.     linenr_t        ue_top;        /* number of line above undo block */
  96.     linenr_t        ue_bot;        /* number of line below undo block */
  97.     linenr_t        ue_lcount;    /* linecount when u_save called */
  98.     char_u            **ue_array;    /* array of lines in undo block */
  99.     long            ue_size;    /* number of lines in ue_array */
  100. };
  101.  
  102. struct u_header
  103. {
  104.     struct u_header    *uh_next;    /* pointer to next header in list */
  105.     struct u_header    *uh_prev;    /* pointer to previous header in list */
  106.     struct u_entry    *uh_entry;    /* pointer to first entry */
  107.     FPOS             uh_cursor;    /* cursor position before saving */
  108.     int                 uh_flags;    /* see below */
  109.     FPOS             uh_namedm[NMARKS];    /* marks before undo/after redo */
  110. };
  111.  
  112. /* values for uh_flags */
  113. #define UH_CHANGED    0x01        /* b_changed flag before undo/after redo */
  114. #define UH_EMPTYBUF    0x02        /* buffer was empty */
  115.  
  116. /*
  117.  * stuctures used in undo.c
  118.  */
  119. #if defined(UNIX) || defined(WIN32) || defined(__EMX__)
  120. # define ALIGN_LONG        /* longword alignment and use filler byte */
  121. # define ALIGN_SIZE (sizeof(long))
  122. #else
  123. # define ALIGN_SIZE (sizeof(short))
  124. #endif
  125.  
  126. #define ALIGN_MASK (ALIGN_SIZE - 1)
  127.  
  128. typedef struct m_info info_t;
  129.  
  130. /*
  131.  * stucture used to link chunks in one of the free chunk lists.
  132.  */
  133. struct m_info
  134. {
  135. #ifdef ALIGN_LONG
  136.     long_u     m_size;    /* size of the chunk (including m_info) */
  137. #else
  138.     short_u  m_size;    /* size of the chunk (including m_info) */
  139. #endif
  140.     info_t    *m_next;    /* pointer to next free chunk in the list */
  141. };
  142.  
  143. /*
  144.  * structure used to link blocks in the list of allocated blocks.
  145.  */
  146. struct m_block
  147. {
  148.     struct m_block    *mb_next;    /* pointer to next allocated block */
  149.     info_t            mb_info;    /* head of free chuck list for this block */
  150. };
  151.  
  152. /*
  153.  * things used in memfile.c
  154.  */
  155.  
  156. typedef struct block_hdr    BHDR;
  157. typedef struct memfile        MEMFILE;
  158. typedef long                blocknr_t;
  159.  
  160. /*
  161.  * for each (previously) used block in the memfile there is one block header.
  162.  * 
  163.  * The block may be linked in the used list OR in the free list.
  164.  * The used blocks are also kept in hash lists.
  165.  *
  166.  * The used list is a doubly linked list, most recently used block first.
  167.  *         The blocks in the used list have a block of memory allocated.
  168.  *        mf_used_count is the number of pages in the used list.
  169.  * The hash lists are used to quickly find a block in the used list.
  170.  * The free list is a single linked list, not sorted.
  171.  *        The blocks in the free list have no block of memory allocated and
  172.  *        the contents of the block in the file (if any) is irrelevant.
  173.  */
  174.  
  175. struct block_hdr
  176. {
  177.     BHDR        *bh_next;            /* next block_hdr in free or used list */
  178.     BHDR        *bh_prev;            /* previous block_hdr in used list */
  179.     BHDR        *bh_hash_next;        /* next block_hdr in hash list */
  180.     BHDR        *bh_hash_prev;        /* previous block_hdr in hash list */
  181.     blocknr_t    bh_bnum;                /* block number */
  182.     char_u        *bh_data;            /* pointer to memory (for used block) */
  183.     int            bh_page_count;        /* number of pages in this block */
  184.  
  185. #define BH_DIRTY    1
  186. #define BH_LOCKED    2
  187.     char        bh_flags;            /* BH_DIRTY or BH_LOCKED */
  188. };
  189.  
  190. /*
  191.  * when a block with a negative number is flushed to the file, it gets
  192.  * a positive number. Because the reference to the block is still the negative
  193.  * number, we remember the translation to the new positive number in the
  194.  * double linked trans lists. The structure is the same as the hash lists.
  195.  */
  196. typedef struct nr_trans NR_TRANS;
  197.  
  198. struct nr_trans
  199. {
  200.     NR_TRANS    *nt_next;            /* next nr_trans in hash list */
  201.     NR_TRANS    *nt_prev;            /* previous nr_trans in hash list */
  202.     blocknr_t    nt_old_bnum;            /* old, negative, number */
  203.     blocknr_t    nt_new_bnum;            /* new, positive, number */
  204. };
  205.  
  206. /*
  207.  * Simplistic hashing scheme to quickly locate the blocks in the used list.
  208.  * 64 blocks are found directly (64 * 4K = 256K, most files are smaller).
  209.  */
  210. #define MEMHASHSIZE        64
  211. #define MEMHASH(nr)        ((nr) & (MEMHASHSIZE - 1))
  212.  
  213. struct memfile
  214. {
  215.     char_u        *mf_fname;            /* name of the file */
  216.     char_u        *mf_xfname;            /* idem, full path */
  217.     int            mf_fd;                /* file descriptor */
  218.     BHDR        *mf_free_first;        /* first block_hdr in free list */
  219.     BHDR        *mf_used_first;        /* mru block_hdr in used list */
  220.     BHDR        *mf_used_last;        /* lru block_hdr in used list */
  221.     unsigned    mf_used_count;        /* number of pages in used list */
  222.     unsigned    mf_used_count_max;    /* maximum number of pages in memory */
  223.     BHDR        *mf_hash[MEMHASHSIZE];    /* array of hash lists */
  224.     NR_TRANS    *mf_trans[MEMHASHSIZE];    /* array of trans lists */
  225.     blocknr_t    mf_blocknr_max;        /* highest positive block number + 1*/
  226.     blocknr_t    mf_blocknr_min;        /* lowest negative block number - 1 */
  227.     blocknr_t    mf_neg_count;        /* number of negative blocks numbers */
  228.     blocknr_t    mf_infile_count;    /* number of pages in the file */
  229.     unsigned    mf_page_size;        /* number of bytes in a page */
  230.     int            mf_dirty;            /* Set to TRUE if there are dirty blocks */
  231. };
  232.  
  233. /*
  234.  * things used in memline.c
  235.  */
  236. typedef struct info_pointer        IPTR;        /* block/index pair */
  237.  
  238. /*
  239.  * When searching for a specific line, we remember what blocks in the tree
  240.  * are the branches leading to that block. This is stored in ml_stack.
  241.  * Each entry is a pointer to info in a block (may be data block or pointer block)
  242.  */
  243. struct info_pointer
  244. {
  245.     blocknr_t    ip_bnum;        /* block number */
  246.     linenr_t    ip_low;            /* lowest lnum in this block */
  247.     linenr_t    ip_high;        /* highest lnum in this block */
  248.     int            ip_index;        /* index for block with current lnum */
  249. };
  250.  
  251. typedef struct memline MEMLINE;
  252.  
  253. /*
  254.  * the memline structure holds all the information about a memline
  255.  */
  256. struct memline
  257. {
  258.     linenr_t    ml_line_count;    /* number of lines in the buffer */
  259.  
  260.     MEMFILE        *ml_mfp;        /* pointer to associated memfile */
  261.  
  262. #define ML_EMPTY        1        /* empty buffer */
  263. #define ML_LINE_DIRTY    2        /* cached line was changed and allocated */
  264. #define ML_LOCKED_DIRTY    4        /* ml_locked was changed */
  265. #define ML_LOCKED_POS    8        /* ml_locked needs positive block number */
  266.     int            ml_flags;
  267.  
  268.     IPTR        *ml_stack;        /* stack of pointer blocks (array of IPTRs) */
  269.     int            ml_stack_top;    /* current top if ml_stack */
  270.     int            ml_stack_size;    /* total number of entries in ml_stack */
  271.  
  272.     linenr_t    ml_line_lnum;    /* line number of cached line, 0 if not valid */
  273.     char_u        *ml_line_ptr;    /* pointer to cached line */
  274.  
  275.     BHDR        *ml_locked;        /* block used by last ml_get */
  276.     linenr_t    ml_locked_low;    /* first line in ml_locked */
  277.     linenr_t    ml_locked_high;    /* last line in ml_locked */
  278.     int            ml_locked_lineadd;    /* number of lines inserted in ml_locked */
  279. };
  280.  
  281. /*
  282.  * buffer: structure that holds information about one file
  283.  *
  284.  * Several windows can share a single Buffer
  285.  * A buffer is unallocated if there is no memfile for it.
  286.  * A buffer is new if the associated file has never been loaded yet.
  287.  */
  288.  
  289. typedef struct buffer BUF;
  290.  
  291. struct buffer
  292. {
  293.     MEMLINE             b_ml;                /* associated memline (also contains
  294.                                          * line count) */
  295.  
  296.     BUF                *b_next;            /* links in list of buffers */
  297.     BUF                *b_prev;
  298.  
  299.     int                 b_changed;            /* 'modified': Set to TRUE if
  300.                                          * something in the file has
  301.                                           * been changed and not written out.
  302.                                          */
  303.  
  304.     int                 b_notedited;        /* Set to TRUE when file name is
  305.                                          * changed after starting to edit, 
  306.                                           * reset when file is written out. */
  307.  
  308.     int              b_nwindows;        /* nr of windows open on this buffer */
  309.  
  310.     int                 b_neverloaded;        /* file has never been loaded into
  311.                                          * buffer, many variables still need
  312.                                          * to be set */
  313.  
  314.     /*
  315.      * b_filename has the full path of the file.
  316.      * b_sfilename is the name as the user typed it.
  317.      * b_xfilename is the same as b_sfilename, unless did_cd is set, then it
  318.      *               is the same as b_filename.
  319.      */
  320.     char_u            *b_filename;
  321.     char_u            *b_sfilename;
  322.     char_u            *b_xfilename;
  323.  
  324.     int                 b_fnum;            /* file number for this file. */
  325.     WINLNUM            *b_winlnum;            /* list of last used lnum for
  326.                                          * each window */
  327.  
  328.     long             b_mtime;            /* last change time of original file */
  329.     long             b_mtime_read;        /* last change time when reading */
  330.  
  331.     FPOS               b_namedm[NMARKS];    /* current named marks (mark.c) */
  332.  
  333.     FPOS             b_last_cursor;        /* cursor position when last unloading
  334.                                            this buffer */
  335.  
  336.     /*
  337.      * Character table, only used in charset.c for 'iskeyword'
  338.      */
  339.     char             b_chartab[256];
  340.  
  341.     /*
  342.      * start and end of an operator, also used for '[ and ']
  343.      */
  344.     FPOS             b_op_start;
  345.     FPOS             b_op_end;
  346.     
  347. #ifdef VIMINFO
  348.     int                 b_marks_read;        /* Have we read viminfo marks yet? */
  349. #endif /* VIMINFO */
  350.  
  351.     /*
  352.      * The following only used in undo.c.
  353.      */
  354.     struct u_header    *b_u_oldhead;        /* pointer to oldest header */
  355.     struct u_header    *b_u_newhead;        /* pointer to newest header */
  356.     struct u_header    *b_u_curhead;        /* pointer to current header */
  357.     int                 b_u_numhead;        /* current number of headers */
  358.     int                 b_u_synced;        /* entry lists are synced */
  359.  
  360.     /*
  361.      * variables for "U" command in undo.c
  362.      */
  363.     char_u            *b_u_line_ptr;        /* saved line for "U" command */
  364.     linenr_t         b_u_line_lnum;        /* line number of line in u_line */
  365.     colnr_t             b_u_line_colnr;    /* optional column number */
  366.  
  367.     /*
  368.      * The following only used in undo.c
  369.      */
  370.     struct m_block     b_block_head;        /* head of allocated memory block list */
  371.     info_t            *b_m_search;         /* pointer to chunk before previously
  372.                                             * allocated/freed chunk */
  373.     struct m_block    *b_mb_current;        /* block where m_search points in */
  374.  
  375.     /*
  376.      * Options "local" to a buffer.
  377.      * They are here because their value depends on the type of file
  378.      * or contents of the file being edited.
  379.      * The "save" options are for when the paste option is set.
  380.      */
  381.     int                 b_p_initialized;    /* set when options initialized */
  382.     int                 b_p_ai, b_p_ro, b_p_lisp;
  383.     int                 b_p_inf;             /* infer case of ^N/^P completions */
  384.     int                 b_p_bin, b_p_eol, b_p_et, b_p_ml, b_p_tx;
  385. #ifndef SHORT_FNAME
  386.     int                 b_p_sn;
  387. #endif
  388.  
  389.     long             b_p_sw, b_p_ts, b_p_tw, b_p_wm;
  390.     char_u            *b_p_fo, *b_p_com, *b_p_isk;
  391.  
  392.     /* saved values for when 'bin' is set */
  393.     long             b_p_wm_nobin, b_p_tw_nobin;
  394.     int                 b_p_tx_nobin, b_p_ta_nobin;
  395.     int                 b_p_ml_nobin, b_p_et_nobin;
  396.  
  397.     /* saved values for when 'paste' is set */
  398.     int                 b_p_ai_save, b_p_lisp_save;
  399.     long             b_p_tw_save, b_p_wm_save;
  400.  
  401. #ifdef SMARTINDENT
  402.     int                 b_p_si, b_p_si_save;
  403. #endif
  404. #ifdef CINDENT
  405.     int                 b_p_cin;        /* use C progam indent mode */
  406.     int                 b_p_cin_save;    /* b_p_cin saved for paste mode */
  407.     char_u            *b_p_cino;        /* C progam indent mode options */
  408.     char_u            *b_p_cink;        /* C progam indent mode keys */
  409. #endif
  410. #if defined(CINDENT) || defined(SMARTINDENT)
  411.     char_u            *b_p_cinw;        /* words extra indent for 'si' and 'cin' */
  412. #endif
  413.  
  414.     char             b_did_warn;    /* Set to 1 if user has been warned on
  415.                                      * first change of a read-only file */
  416.     char             b_help;        /* buffer for help file */
  417.  
  418. #ifndef SHORT_FNAME
  419.     int                 b_shortname;    /* this file has an 8.3 filename */
  420. #endif
  421. };
  422.  
  423. /*
  424.  * Structure which contains all information that belongs to a window
  425.  *
  426.  * All row numbers are relative to the start of the window, except w_winpos.
  427.  */
  428.  
  429. struct window
  430. {
  431.     BUF            *w_buffer;             /* buffer we are a window into */
  432.  
  433.     WIN            *w_prev;            /* link to previous window (above) */
  434.     WIN            *w_next;            /* link to next window (below) */
  435.  
  436.     FPOS        w_cursor;            /* cursor's position in buffer */
  437.  
  438.     /*
  439.      * These elements are related to the cursor's position in the window.
  440.      * This is related to character positions in the window, not in the file.
  441.      */
  442.     int            w_row, w_col;        /* cursor's position in window */
  443.  
  444.     /*
  445.      * w_cline_height is set in cursupdate() to the number of physical lines
  446.      * taken by the buffer line that the cursor is on.  We use this to avoid
  447.      * extra calls to plines().  Note that w_cline_height and w_cline_row are
  448.      * only valid after calling cursupdate(), until the next vertical movement
  449.      * of the cursor or change of text.
  450.      */
  451.     int            w_cline_height;        /* current size of cursor line */
  452.  
  453.     int            w_cline_row;        /* starting row of the cursor line */
  454.  
  455.     colnr_t        w_virtcol;            /* column number of the file's actual */
  456.                                     /* line, as opposed to the column */
  457.                                     /* number we're at on the screen. */
  458.                                     /* This makes a difference on lines */
  459.                                     /* which span more than one screen */
  460.                                     /* line. */
  461.  
  462.     colnr_t        w_curswant;            /* The column we'd like to be at. */
  463.                                     /* This is used to try to stay in */
  464.                                     /* the same column through up/down */
  465.                                     /* cursor motions. */
  466.  
  467.     int            w_set_curswant;        /* If set, then update w_curswant */
  468.                                     /* the next time through cursupdate() */
  469.                                     /* to the current virtual column */
  470.  
  471.     /*
  472.      * the next three are used to update the visual part
  473.      */
  474.     linenr_t    w_old_cursor_lnum;    /* last known end of visual part */
  475.     colnr_t        w_old_cursor_vcol;    /* last known end of visual part */
  476.     linenr_t    w_old_visual_lnum;    /* last known start of visual part */
  477.     colnr_t        w_old_curswant;        /* last known value of Curswant */
  478.  
  479.     linenr_t    w_topline;            /* number of the line at the top of
  480.                                      * the screen */
  481.     linenr_t    w_botline;            /* number of the line below the bottom
  482.                                      * of the screen */
  483.     int            w_empty_rows;        /* number of ~ rows in window */
  484.  
  485.     int            w_winpos;            /* row of topline of window in screen */
  486.     int            w_height;            /* number of rows in window, excluding
  487.                                         status/command line */
  488.     int            w_status_height;    /* number of status lines (0 or 1) */
  489.  
  490.     int            w_redr_status;        /* if TRUE status line must be redrawn */
  491.     int            w_redr_type;        /* type of redraw to be performed on win */
  492.  
  493.     colnr_t        w_leftcol;            /* starting column of the screen */
  494.  
  495. /*
  496.  * The height of the lines currently in the window is remembered
  497.  * to avoid recomputing it every time. The number of entries is w_nrows.
  498.  */
  499.     int             w_lsize_valid;        /* nr. of valid LineSizes */
  500.     linenr_t     *w_lsize_lnum;        /* array of line numbers for w_lsize */
  501.     char_u          *w_lsize;            /* array of line heights */
  502.  
  503.     int            w_alt_fnum;            /* alternate file (for # and CTRL-^) */
  504.  
  505.     int            w_arg_idx;            /* current index in argument list */
  506.     int            w_arg_idx_invalid;    /* editing another file then w_arg_idx */
  507.  
  508.     /*
  509.      * Variables "local" to a window.
  510.      * They are here because they influence the layout of the window or
  511.      * depend on the window layout.
  512.      */
  513.     int            w_p_list,
  514.                 w_p_nu,
  515. #ifdef RIGHTLEFT
  516.                 w_p_rl,
  517. #endif
  518.                 w_p_wrap,
  519.                 w_p_lbr;
  520.     long        w_p_scroll;
  521.  
  522.     /*
  523.      * The w_prev_pcmark field is used to check whether we really did jump to
  524.      * a new line after setting the w_pcmark.  If not, then we revert to
  525.      * using the previous w_pcmark.
  526.      */
  527.     FPOS        w_pcmark;            /* previous context mark */
  528.     FPOS        w_prev_pcmark;        /* previous w_pcmark */
  529.  
  530.     /*
  531.      * the jumplist contains old cursor positions
  532.      */
  533.     struct filemark w_jumplist[JUMPLISTSIZE];
  534.     int             w_jumplistlen;                /* number of active entries */
  535.     int                w_jumplistidx;                /* current position */
  536.  
  537.     /*
  538.      * the tagstack grows from 0 upwards:
  539.      * entry 0: older
  540.      * entry 1: newer
  541.      * entry 2: newest
  542.      */
  543.     struct taggy    w_tagstack[TAGSTACKSIZE];    /* the tag stack */
  544.     int                w_tagstackidx;                /* idx just below activ entry */
  545.     int                w_tagstacklen;                /* number of tags on stack */
  546.  
  547. #ifdef USE_GUI
  548.     GuiScrollbar    w_scrollbar;                /* Scrollbar for this window */
  549. #endif /* USE_GUI */
  550. };
  551.